import { BasicColumn, FormSchema } from '@/components/Table';
import { dateUtil } from '@/utils/dateUtil';

export const articleColumns: BasicColumn[] = [
  {
    title: '标题',
    dataIndex: 'title',
    width: 50,
  },
  {
    title: '分类',
    dataIndex: 'name',
    width: 50,
  },
  {
    title: '来源',
    dataIndex: 'source',
    width: 50,
  },
  {
    title: '更新时间',
    dataIndex: 'modifyDate',
    width: 160,
    customRender: ({ text }) => {
      return dateUtil(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
  {
    title: '浏览次数',
    dataIndex: 'hits',
    width: 50,
  },
  {
    title: '排序',
    dataIndex: 'sort',
    width: 50,
  },
  {
    title: '发布状态',
    dataIndex: 'isPublication',
    width: 50,
    customRender: ({ text }) => {
      if (text) {
        return '已发布';
      } else if (!text) {
        return '未发布';
      }
    },
  },
];
export const articleSearchFormSchema: FormSchema[] = [
  {
    field: 'cid',
    label: '分类',
    component: 'ApiSelect',
    componentProps: {
      api: '/article/article/categoryList',
      treeDefaultExpandAll: false,
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
    },
    required: false,
  },
  {
    field: 'startTime',
    label: '开始时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'endTime',
    label: '结束时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'keyword',
    label: '标题名称',
    component: 'Input',
    colProps: {
      span: 5,
    },
  },
];
export const articleFormSchema: FormSchema[] = [
  // {
  //   field: 'groupsId',
  //   label: '分组',
  //   component: 'ApiSelect',
  //   componentProps: {
  //     api: '/admin/groups/list',
  //     treeDefaultExpandAll: false,
  //     fieldNames: {
  //       label: 'name',
  //       key: 'id',
  //       value: 'id',
  //     },
  //   },
  //   colProps: {
  //     span: 5,
  //   },
  // },
  {
    field: 'name',
    label: '优惠券名称',
    component: 'Input',
  },
  {
    field: 'amount',
    label: '优惠券金额',
    component: 'InputNumber',
    componentProps: {
      precision: 2,
      min: 0,
      max: 100000000,
    },
    required: true,
  },
  {
    field: 'startTime',
    label: '开始时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    required: true,
  },
  {
    field: 'endTime',
    label: '结束时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    required: true,
  },
  {
    field: 'byFull',
    label: '满多少可以使用优惠',
    component: 'InputNumber',
    componentProps: {
      precision: 2,
      min: 0,
      max: 100000000,
    },
    required: true,
  },
  {
    field: 'expression',
    label: '优惠券表达式',
    helpMessage: 'price代表订单金额,service代表服务费,例如price*0.8-service',
    component: 'Input',
  },
  {
    field: 'permissions',
    label: '可使用场站',
    component: 'CheckboxGroup',
    componentProps: {
      // options: [
      //   { label: '充电管理', value: '1' },
      //   { label: '车辆管理', value: '2' },
      //   { label: '订单管理', value: '3' },
      //   { label: '发票管理', value: '4' },
      //   { label: '系统管理', value: '6' },
      // ],
    },
  },

];